/**
 * Created by tdzl2003 on 9/10/16.
 */

import React, { PropTypes } from 'react';
import FormModal from '../../components/FormModal';
import {Form, Input} from 'antd';
import {post} from '../../logics/rpc';
import alert from '../../utils/alert';

@Form.create()
export default class AddAccModal extends React.Component {
    onReturn = ev => {
        this.refs.form.submit();
    };
    roleName = {
        name:  {
            rules: [
                {
                    required: true, message: '请输入角色名字' },
            ],
        }
    };
    submit = async ({name}) => {
        await post('/admin/role/create', {
            name
        });
        alert('创建成功');
        const {onAdded} = this.props;
        onAdded && onAdded();
    };
    render() {
        const { roleName } = this;
        const { getFieldProps } = this.props.form;
        return (
            <FormModal
                ref="form"
                title="添加角色"
                okTitle="确 定"
                onSubmit={this.submit}
                {...this.props}
            >
                <Form.Item label="请输入角色名字">
                    <Input {...getFieldProps('name', roleName.name)} onPressEnter={this.onReturn} />
                </Form.Item>

            </FormModal>
        );
    }
}
